package it.canraid.texthere;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

import android.app.Activity;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class McommentArrayAdapter extends ArrayAdapter<Ecomment> {
	private Activity context;
	private ArrayList<Ecomment> values=null;
	public String at_aux=null;
	public String on_aux=null;
	public String hasComment=null;
	public SimpleDateFormat sf=null;
	public int colorStrongLine=0;
	public int space_little=0;
	
	private class ViewHolder {
	    public TextView textName;
	    public TextView textComment;
	    public TextView textDateCreated;
	    public TextView textQtyLike;
	    public TextView textQtyUnlike;
	  }
	
	public McommentArrayAdapter(Activity context, ArrayList<Ecomment> values) {
		super(context, R.layout.msg_item, values);
		this.context = context;
		this.values = values;
		init();
	}
	
	private void init(){
		at_aux=context.getResources().getString(R.string.at_date);
		on_aux=context.getResources().getString(R.string.on_date);
		space_little=(int) context.getResources().getDimension(R.dimen.space_little);
		hasComment=context.getResources().getString(R.string.has_commented);
		sf=new SimpleDateFormat("'"+at_aux+" ' HH:mm ' "+on_aux+" ' dd-MM-yyyy", Locale.ITALY);
		colorStrongLine=context.getResources().getColor(R.color.background_strong_line);
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder idTxt=null;
		View rowView=convertView;
		if (rowView==null){
			idTxt=new ViewHolder();
			LayoutInflater inflater = context.getLayoutInflater();
			rowView = inflater.inflate(R.layout.msg_item, null);
			View panelMain = rowView.findViewById(R.id.panelMainMsg);
			panelMain.setBackgroundResource(R.layout.background_comment);
			idTxt.textName = (TextView) rowView.findViewById(R.id.textName);
			idTxt.textComment = (TextView) rowView.findViewById(R.id.textMessage);
			idTxt.textDateCreated = (TextView) rowView.findViewById(R.id.textDateCreated);
			idTxt.textQtyLike = (TextView) rowView.findViewById(R.id.textQtyLike);
			idTxt.textQtyUnlike = (TextView) rowView.findViewById(R.id.textQtyUnlike);
			View panelComment=rowView.findViewById(R.id.panelComment);
			panelComment.setVisibility(View.GONE);
			TextView textHasWritten=(TextView)rowView.findViewById(R.id.textHaveHasWritten);
			textHasWritten.setText(hasComment);
			
			rowView.setTag(idTxt);
		}
		idTxt=(ViewHolder)rowView.getTag();
		idTxt.textName.setText(values.get(position).STX_USERID_CASE_SENSITIVE);
		idTxt.textComment.setText(values.get(position).LTX_COMMENT);
		idTxt.textDateCreated.setText(sf.format(new Date(values.get(position).TMS_CREATED)));
		idTxt.textQtyUnlike.setText(Integer.toString(values.get(position).QTY_UNLIKE));
		idTxt.textQtyLike.setText(Integer.toString(values.get(position).QTY_LIKE));
		
		return rowView;
	}
}